package com.qitmiaojie.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qitmiaojie.controller.utils.Result;
import com.qitmiaojie.pojo.Activity;
import com.qitmiaojie.pojo.dto.AdviceMsg;
import com.qitmiaojie.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
public class AdviceController {

    @Autowired
    private ActivityService activityService;



    @DeleteMapping("/advice/activity/{id}")
    public Result deleteById(@PathVariable("id") Integer id){
        activityService.removeById(id);
        return new Result(200,"删除成功",null);
    }


    @PostMapping("/advice/activity")
    public Result addActivity(@RequestBody Activity activity){
        log.info(activity.toString());
        activityService.saveOrUpdate(activity);
        return new Result(200,"发布成功",null);
    }

    @GetMapping("/advice/activity")
    public Result getAllActivity(@RequestParam(value = "Name",required = false) String Name,
                                 @RequestParam(value = "CurrentPage",required = false,defaultValue = "1") Integer CurrentPage,
                                 @RequestParam(value = "Size", required = false,defaultValue = "10") Integer Size){

        IPage<Activity>  activityIPage = activityService.selectByPage(CurrentPage,Size,Name);
        log.info("pages" + activityIPage.getPages()+" total   " +activityIPage.getTotal() + "current " +activityIPage.getCurrent() );
        return new Result(200,"查询成功",activityIPage);
    }
    @GetMapping("/advice/activity/{id}")
    public Result getActivityById(@PathVariable Integer id){
        Activity activity = activityService.getById(id);
        return new Result(200,"查询成功",activity);
    }
    @GetMapping("/advice/competitionMsg")
    public Result getMsg(){
        List<AdviceMsg> adviceMsg = activityService.getMsg();
        return new Result(200,"查询成功",adviceMsg);
    }




}
